//
//  USAccountController.m
//  us
//
//  Created by karry on 2025/4/8.
//

#import "USAccountController.h"
#import "USUnmatchController.h"
#import "SceneDelegate.h"
#import "USWriteOffUserController.h"
@interface USAccountController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSArray *items;

@end

@implementation USAccountController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"账户";
//    解除匹配，手机号，注销账户，退出登陆

    [self setupData];
    [self setupUI];

}

- (void)loadData{
    [super loadData];
    
}

- (void)setupData{
    USUser *user = [USUser user];
 
    DTItem *item0 = [DTItem itemWithTitle:@"解除匹配" image:nil tag:0 identifier:nil handle:nil];
    DTItem *item1 = [DTItem itemWithTitle:@"手机号" detailTitle:user.mobile image:nil tag:1 identifier:nil handle:nil];
    DTItem *item2 = [DTItem itemWithTitle:@"注销账户" image:nil tag:2 identifier:nil handle:nil];
    
    if (USUser.user.relStatus == 1) {
        self.items = @[item0,item1,item2];
    }else{
        self.items = @[item1,item2];
    }
    
}

- (void)setupUI{
    
    self.us_tableView.delegate = self;
    self.us_tableView.dataSource = self;
    [self.tableView reloadData];
    
    UIButton *logOutBtn = [UIButton us_borderButtonWithTitle:@"退出登录"];
    [self.view addSubview:logOutBtn];
    
    [logOutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(32);
        make.right.mas_offset(-32);
        make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom).mas_offset(-20);
        make.height.mas_equalTo(56);
    }];
    
    @weakify(self)
    [[logOutBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            
        @strongify(self)
        [self logoutAction];
    }];
    
}

- (void)logoutAction {
    
    [USFeedbackTool impactSoft];
    
    [USUser cancelLogin];
}


#pragma mark -  <UITableViewDelegate,UITableViewDataSource>

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DTItem *item = self.items[indexPath.row];
    if (item.tag == 0) {
        USUnmatchController *vc = [USUnmatchController new];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (item.tag == 2) {
        USWriteOffUserController *vc = [USWriteOffUserController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [UITableViewCell us_defaultCell];
    DTItem *item = self.items[indexPath.row];
    cell.textLabel.text = item.title;
    cell.detailTextLabel.text = item.detailTitle;

    [cell us_setDefaultArrow];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [UITableViewCell us_defaultCellRowHeight];
}


@end
